package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.DiscountCard;
import com.addplus.townmall.server.api.model.town.expand.DiscountInformationExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 商城会员卡内容表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface DiscountCardMapper extends BaseAddMapper<DiscountCard> {

    @Select("SELECT\n" +
            " m.id,\n" +
            " m.head_portrait,\n" +
            " IFNULL(i.integral_now,0) as integral_now,\n" +
            " d.discount_card_id as legal_right_count\n" +
            "FROM\n" +
            " member m\n" +
            " LEFT JOIN member_integral i ON m.id = i.member_id\n" +
            " LEFT JOIN discount_card_member d on m.id = d.member_id AND d.is_deleted = 0 AND d.discuount_status = 1\n" +
            "WHERE\n" +
            " m.id = #{memberId} AND m.is_deleted = 0 order By d.offer_amount LIMIT 1")
    DiscountInformationExpand getDiscountInformationById(@Param("memberId") Integer memberId);


    /*判断会员卡名称是否重复*/
    @Select("select dc.name from discount_card dc where dc.name =#{cardName} and dc.is_deleted =0")
    DiscountCard checkNameExist(@Param("cardName") String cardName);
}
